# -*-coding: Utf-8 -*-
# @File : config .py
# author: Chimengmeng
# blog_url : https://www.cnblogs.com/dream-ze/
# Time：2023/10/2
# 基本配置文件

import os
from core.Utils import create_file_name
from dotenv import load_dotenv, find_dotenv
from pydantic import BaseSettings
from typing import List

# 项目根目录
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# 静态资源文件夹
STATIC_DIR = os.path.join(BASE_DIR, "static")
create_file_name(STATIC_DIR)

# 模板文件文件夹
TEMPLATE_DIR = os.path.join(STATIC_DIR, "templates")
create_file_name(TEMPLATE_DIR)

# 调试模式
APP_DEBUG = True

# 项目信息
VERSION = "0.0.1"

# 项目名字
PROJECT_NAME = "fasdapi"

# 项目描述
DESCRIPTION = '<a href="/redoc" target="_blank">redoc</a>'

# 跨域请求
# 允许跨越域名
# CORS_ORIGINS = ["*"]
CORS_ORIGINS = ["*"]
# 是否允许跨域
# CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_CREDENTIALS = True
# 允许跨域的请求方式
CORS_ALLOW_METHODS = ["*"]
# 允许跨域的请求头
CORS_ALLOW_HEADERS = ["*"]

# Session 配置
SECRET_KEY = "session"
SESSION_COOKIE = "session_id"
SESSION_MAX_AGE = 14 * 24 * 60 * 60

# Jwt 配置
# jwt 秘钥
JWT_SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
# jwt 加密算法
JWT_ALGORITHM = "HS256"
# jwt 大小
JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 24 * 60

# OAUTH2 密码认证回调 URL
SWAGGER_UI_OAUTH2_REDIRECT_URL = "/api/v1/test/oath2"

# 二维码过期时间
QRCODE_EXPIRE = 60 * 1


class Config(BaseSettings):
    # 加载环境变量
    load_dotenv(find_dotenv(), override=True)
    APP_DEBUG: bool = APP_DEBUG
    VERSION: str = VERSION
    PROJECT_NAME: str = PROJECT_NAME
    DESCRIPTION: str = DESCRIPTION
    STATIC_DIR: str = STATIC_DIR
    TEMPLATE_DIR: str = TEMPLATE_DIR
    CORS_ORIGINS: List = CORS_ORIGINS
    CORS_ALLOW_CREDENTIALS: bool = CORS_ALLOW_CREDENTIALS
    CORS_ALLOW_METHODS: List = CORS_ALLOW_METHODS
    CORS_ALLOW_HEADERS: List = CORS_ALLOW_HEADERS
    SECRET_KEY = SECRET_KEY
    SESSION_COOKIE = SESSION_COOKIE
    SESSION_MAX_AGE = SESSION_MAX_AGE
    JWT_SECRET_KEY = JWT_SECRET_KEY
    JWT_ALGORITHM = JWT_ALGORITHM
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES = JWT_ACCESS_TOKEN_EXPIRE_MINUTES
    SWAGGER_UI_OAUTH2_REDIRECT_URL = SWAGGER_UI_OAUTH2_REDIRECT_URL
    QRCODE_EXPIRE = QRCODE_EXPIRE


# 创建配置对象
settings = Config()
